package top.datacluster.basic.algorithm.leetcode.dynamic;

public class LeetCode746 {

    public int minCostClimbingStairs(int[] cost) {
        if (cost.length == 0 || cost.length == 1){
            return 0;
        }
        if (cost.length == 2){
            return Math.min(cost[0], cost[1]);
        }
        int[] result = new int[cost.length];
        result[0] = cost[0];
        result[1] = cost[1];
        for (int i = 2; i < cost.length; i++){
            result[i] = Math.min(result[i - 2], result[i - 1]) + cost[i];
        }
        return Math.min(result[result.length - 1], result[result.length - 2]);
    }

    public static void main(String[] args) {
        int[] test = new int[]{1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        System.out.println(new LeetCode746().minCostClimbingStairs(test));
    }
}
